import { _decorator, Component, Node } from 'cc';
import { PlatformType, SDKSystem } from '../../SystemSDK/SDKSystem';
import { StorageSystem } from '../../SystemStorage/StorageSystem';
import { UIEnum } from '../../SystemUI/UIEnum';
import EventManager from '../EventManager';
import { EventTypes } from '../EventTypes';
import { TTAdvertUIConfig, WXAdvertUIConfig } from './AdvertUIConfig';
const { ccclass, property } = _decorator;
/**广告管理 */
@ccclass('AdvertManager')
export class AdvertManager extends Component {
    @property
    testBanner = false;

    onLoad() {
        this.onEvents();
        this.node.children[0].active = this.testBanner;
    }

    onEvents() {
        EventManager.on(EventTypes.GameEvents.UIChanged, this.onUIChanged, this);
    }

    onUIChanged(ui: UIEnum) {
        if (StorageSystem.getData().levelAssets.curLv == 1) return;
        //根据当前UI 加载广告数据
        let _cfg;
        switch (SDKSystem._curPlatform) {
            case PlatformType.WXMiniGame:
                _cfg = WXAdvertUIConfig[ui];
                break;
            case PlatformType.PCMiniGame:
            case PlatformType.TTMiniGame:
                _cfg = TTAdvertUIConfig[ui];
                break;
            default:
                break;
        }

        //-------------banner
        if (!!_cfg) {
            if (_cfg.banner) {
                EventManager.emit(EventTypes.SDKEvents.ShowBanner);
            } else {
                EventManager.emit(EventTypes.SDKEvents.HideBanner);
            }
            this.node.children[0].active = (this.testBanner || SDKSystem._curPlatform == PlatformType.PCMiniGame) && _cfg.banner;
        }

        //--------------原生模板广告 5x5
        if (!!_cfg && !!_cfg.customAd5x5) {
            EventManager.emit(EventTypes.SDKEvents.ShowCustomAd, _cfg.customAd5x5.adId);
        } else {
            // EventManager.emit(EventTypes.SDKEvents.HideCustomAd, 0);
        }

    }

}
